package com.oa.co.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.co.mapper.LeaveInformationAdminMapper;
import com.oa.co.pojo.LeaveInformation;
import com.oa.co.service.LeaveInformationAdminService;
import com.oa.co.vo.DepartmentBarVo;
import com.oa.co.vo.DepartmentPieVo;
import com.oa.co.vo.LeaveInformationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhao chen qi
 * @date 2023/5/8 17:29
 */
@Service("leaveInformationAdminService")
public class LeaveInformationAdminServiceImpl implements LeaveInformationAdminService {
    @Autowired
    LeaveInformationAdminMapper leaveInformationAdminMapper;


    @Override
    public PageInfo<LeaveInformation> selectStaffLeaveRequestList(String applicant, String subordinate_department, Integer pageNum, Integer limit) {
        LeaveInformation leaveInformation = new LeaveInformation();
        leaveInformation.setApplicant(applicant);
        leaveInformation.setSubordinate_department(subordinate_department);
        if (pageNum != null && limit != null){

            PageHelper.startPage(pageNum,limit);
            List<LeaveInformation> leaveInformations = leaveInformationAdminMapper.selectStaffLeaveRequestList(leaveInformation);

            PageInfo<LeaveInformation> page = new PageInfo<>(leaveInformations);

            return page;
        }else {
            List<LeaveInformation> leaveInformations = leaveInformationAdminMapper.selectStaffLeaveRequestList(leaveInformation);

            PageInfo<LeaveInformation> page = new PageInfo<>(leaveInformations);

            return page;
        }

    }

    @Override
    public List<DepartmentBarVo> getBarData() {
        return leaveInformationAdminMapper.getBarData();
    }

    @Override
    public List<DepartmentPieVo> getPieData() {
        return leaveInformationAdminMapper.getPieData();
    }

    @Override
    public int editStaff(LeaveInformation leaveInformation) {
        return leaveInformationAdminMapper.editStaff(leaveInformation);
    }

    @Override
    public int addLeaveInformationData(LeaveInformation leaveInformation) {
        return leaveInformationAdminMapper.addLeaveInformationData(leaveInformation);
    }

    @Override
    public int deleteStaff(Integer id) {
        return leaveInformationAdminMapper.deleteStaff(id);
    }

    @Override
    public PageInfo<LeaveInformationVo> selectStaffLeaveRequestList2(String applicant, String subordinate_department, Integer pageNum, Integer limit) {
        LeaveInformationVo leaveInformationVo = new LeaveInformationVo();

        leaveInformationVo.setApplicant(applicant);

        leaveInformationVo.setSubordinate_department(subordinate_department);

        if (pageNum != null && limit != null){

            PageHelper.startPage(pageNum,limit);
            List<LeaveInformationVo> leaveInformations = leaveInformationAdminMapper.selectStaffLeaveRequestList2(leaveInformationVo);

            PageInfo<LeaveInformationVo> page = new PageInfo<>(leaveInformations);

            return page;
        }else {
            List<LeaveInformationVo> leaveInformations = leaveInformationAdminMapper.selectStaffLeaveRequestList2(leaveInformationVo);

            PageInfo<LeaveInformationVo> page = new PageInfo<>(leaveInformations);

            return page;
        }

    }


}
